<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>

    // 给对象添加属性和修改属性
    //Object.defineProperty(obj,key) 

    var room = {
      name: "张三",
      price: 180,
      address: "天安门对面"
    }
    //参数1 要操作的对象   
    //参数2 要操作的属性key
    /* 参数3 {
           value：对象的值
          writable: true，  //true可以修改  false 不可以修改  默认false
          configurable:true,//true 能删除  false 不能删除   默认false 
          enumerable:true,  //true 能遍历 false 不能遍历   默认false
     }
    */
    Object.defineProperty(room, "phone", {
      value: "18812345678",
      writable: true,
      configurable: false,
      enumerable: true
    })
    // room.phone = "123898123"
    delete room.phone
    console.log(room)
    // 遍历
    for (var x in room) {
      console.log(room[x])
    }

  </script>
</body>

</html>